﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using TGIApp.Model;
using System.ServiceModel.Activation;
using TGIApp.Business;

namespace TGIApp.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "TgiService" in code, svc and config file together.
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    [CustomErrorHandlerBehavior]
    public class TgiService : ITgiService
    {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


        #region User
        #region Client
        public List<User> GetAllClients()
        {
            var business = new Business.TgiService();
            var clients = business.GetAllClients();
            log.DebugFormat("{0} clients returned.", clients.Count);
            return clients;
        }

        public User GetClientById(int id)
        {
            var business = new Business.TgiService();
            var client = business.GetClientById(id);
            return client;
        }

        public void CreateClient(User user)
        {
            var business = new Business.TgiService();
            business.CreateClient(user);

        }

        public void UpdateClient(User user)
        {
            var business = new Business.TgiService();
            business.UpdateClient(user);
        }

        public void DeleteClient(User user)
        {
            var business = new Business.TgiService();
            business.DeleteClient(user);
        }

        public void DeleteClientById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteClientById(id);
        }
        #endregion

        #region Agent
        public List<User> GetAllAgents()
        {
            var business = new Business.TgiService();
            var agents = business.GetAllAgents();
            return agents;
        }

        public User GetAgentById(int id)
        {
            var business = new Business.TgiService();
            var agent = business.GetAgentById(id);
            return agent;
        }

        public void CreateAgent(User user)
        {
            var business = new Business.TgiService();
            business.CreateAgent(user);
        }

        public void UpdateAgent(User user)
        {
            var business = new Business.TgiService();
            business.UpdateAgent(user);
        }

        public void DeleteAgent(User user)
        {
            var business = new Business.TgiService();
            business.DeleteAgent(user);
        }

        public void DeleteAgentById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteAgentById(id);
        }
        #endregion

        #region Customer
        public List<User> GetAllCustomers()
        {
            var business = new Business.TgiService();
            var customers = business.GetAllCustomers();
            return customers;
        }

        public User GetCustomerById(int id)
        {
            var business = new Business.TgiService();
            var customer = business.GetCustomerById(id);
            return customer;
        }

        public void CreateCustomer(User user)
        {
            var business = new Business.TgiService();
            business.CreateCustomer(user);
        }

        public void UpdateCustomer(User user)
        {
            var business = new Business.TgiService();
            business.UpdateCustomer(user);
        }

        public void DeleteCustomer(User user)
        {
            var business = new Business.TgiService();
            business.DeleteCustomer(user);
        }

        public void DeleteCustomerById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteCustomerById(id);
        }

        #endregion
        #endregion

        #region Role
        public List<string> GetRolesForUser(string userName)
        {
            var business = new ProviderHelper();
            return business.GetRolesForUser(userName);
        }
        public List<Role> GetAllRoles()
        {
            var business = new Business.TgiService();
            var roles = business.GetAllRoles();
            return roles;
        }

        public Role GetRoleById(int id)
        {
            var business = new Business.TgiService();
            var role = business.GetRoleById(id);
            return role;
        }

        public void CreateRole(Role role)
        {
            var business = new Business.TgiService();
            business.CreateRole(role);
        }

        public void UpdateRole(Role role)
        {
            var business = new Business.TgiService();
            business.UpdateRole(role);
        }
        //TODO: delete dependent objects first
        public void DeleteRole(Role role)
        {
            var business = new Business.TgiService();
            business.DeleteRole(role);
        }
        //TODO: delete dependent objects first
        public void DeleteRoleById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteRoleById(id);
        }
        #endregion

        #region Event
        public List<Event> GetAllEvents()
        {
            var business = new Business.TgiService();
            var events = business.GetAllEvents();
            return events;
        }

        public Event GetEventById(int id)
        {
            var business = new Business.TgiService();
            var evnt = business.GetEventById(id);
            return evnt;
        }

        public void CreateEvent(Event evnt)
        {
            var business = new Business.TgiService();
            business.CreateEvent(evnt);
        }

        public void UpdateEvent(Event evnt)
        {
            var business = new Business.TgiService();
            business.UpdateEvent(evnt);
        }

        public void DeleteEvent(Event evnt)
        {
            var business = new Business.TgiService();
            business.DeleteEvent(evnt);
        }

        public void DeleteEventById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteEventById(id);
        }

        #endregion

        #region Venue
        public List<Venue> GetAllVenues()
        {
            var business = new Business.TgiService();
            var venues = business.GetAllVenues();
            return venues;
        }

        public Venue GetVenueById(int id)
        {
            var business = new Business.TgiService();
            var venue = business.GetVenueById(id);
            return venue;
        }

        public void CreateVenue(Venue venue)
        {
            var business = new Business.TgiService();
            business.CreateVenue(venue);
        }

        public void UpdateVenue(Venue venue)
        {
            var business = new Business.TgiService();
            business.UpdateVenue(venue);
        }

        public void DeleteVenue(Venue venue)
        {
            var business = new Business.TgiService();
            business.DeleteVenue(venue);
        }

        public void DeleteVenueById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteVenueById(id);
        }
        #endregion

        #region Ticket, TicketType, TicketTemplate, TicketQuota
        #region Ticket
        public List<Ticket> GetAllTickets()
        {
            var business = new Business.TgiService();
            return business.GetAllTickets();
        }

        public Ticket GetTicketById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreatTicket(Ticket ticket)
        {
            throw new NotImplementedException();
        }

        public void UpdateTicket(Ticket ticket)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicket(Ticket ticket)
        {
            throw new NotImplementedException();
        }

        public void DeleteTicketById(int id)
        {
            throw new NotImplementedException();
        }
        public List<Ticket> GetAllTicketsByEventIdAndVenueId(int event_id, int venue_id)
        {
            var business = new Business.TgiService();
            return business.GetAllTicketsByEventIdAndVenueId(event_id, venue_id);
        }
        public List<Ticket> GetTicketsByAgentBranchNTicketTypeNQty(int agentBranchId, int ticketTypeId, int sellQty)
        {
            var business = new Business.TgiService();
            return business.GetTicketsByAgentBranchNTicketTypeNQty(agentBranchId, ticketTypeId, sellQty);
        }


        public void SellTickets(int ticketTypeId, int agentBranchId, int customerId, int quantity, int paymentModeId, decimal TotalAmount)
        {
            var business = new Business.TgiService();
            business.SellTickets(ticketTypeId, agentBranchId, customerId, quantity, paymentModeId, TotalAmount);
        }
        #endregion

        #region TicketType
        public List<TicketType> GetAllTicketTypes()
        {
            var business = new Business.TgiService();
            var ticketTypes = business.GetAllTicketTypes();
            return ticketTypes;
        }

        public TicketType GetTicketTypeById(int id)
        {
            var business = new Business.TgiService();
            var ticketType = business.GetTicketTypeById(id);
            return ticketType;
        }

        public void CreatTicketType(TicketType ticketType)
        {
            var business = new Business.TgiService();
            business.CreatTicketType(ticketType);
        }

        public void UpdateTicketType(TicketType ticketType)
        {
            var business = new Business.TgiService();
            business.UpdateTicketType(ticketType);
        }

        public void DeleteTicketType(TicketType ticketType)
        {
            var business = new Business.TgiService();
            business.DeleteTicketType(ticketType);
        }

        public void DeleteTicketTypeById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteTicketTypeById(id);
        }
        public List<TicketType> GetAllTicketTypesWithEventVenue()
        {
            var business = new Business.TgiService();
            return business.GetAllTicketTypesWithEventVenue();
        }
        #endregion

        #region TicketTemplate
        public List<TicketTemplate> GetAllTicketTemplates()
        {
            var business = new Business.TgiService();
            var ticketTemplates = business.GetAllTicketTemplates();
            return ticketTemplates;
        }

        public TicketTemplate GetTicketTemplateById(int id)
        {
            var business = new Business.TgiService();
            var ticketTemplate = business.GetTicketTemplateById(id);
            return ticketTemplate;
        }

        public void CreatTicketTemplate(TicketTemplate ticketTemplate)
        {
            var business = new Business.TgiService();
            business.CreatTicketTemplate(ticketTemplate);
        }

        public void UpdateTicketTemplate(TicketTemplate ticketTemplate)
        {
            var business = new Business.TgiService();
            business.UpdateTicketTemplate(ticketTemplate);
        }

        public void DeleteTicketTemplate(TicketTemplate ticketTemplate)
        {
            var business = new Business.TgiService();
            business.DeleteTicketTemplate(ticketTemplate);
        }

        public void DeleteTicketTemplateById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteTicketTemplateById(id);
        }
        #endregion

        #region TicketQuota
        public List<TicketQuota> GetAllTicketQuotas()
        {
            var business = new Business.TgiService();
            var ticketQuotas = business.GetAllTicketQuotas();
            return ticketQuotas;
        }

        public TicketQuota GetTicketQuotaById(int id)
        {
            var business = new Business.TgiService();
            var ticketQuota = business.GetTicketQuotaById(id);
            return ticketQuota;
        }

        public void CreatTicketQuota(TicketQuota ticketQuota)
        {
            var business = new Business.TgiService();
            business.CreatTicketQuota(ticketQuota);
        }

        public void UpdateTicketQuota(TicketQuota ticketQuota)
        {
            var business = new Business.TgiService();
            business.UpdateTicketQuota(ticketQuota);
        }

        public void DeleteTicketQuota(TicketQuota ticketQuota)
        {
            var business = new Business.TgiService();
            business.DeleteTicketQuota(ticketQuota);
        }

        public void DeleteTicketQuotaById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteTicketQuotaById(id);
        }
        public TicketQuota GetTicketQuotaLoadedById(int id)
        {
            var business = new Business.TgiService();
            return business.GetTicketQuotaLoadedById(id);
        }
        #endregion
        #endregion

        #region Payment
        public List<Payment> GetAllPayments()
        {
            throw new NotImplementedException();
        }

        public Payment GetPaymentById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreatePayment(Payment payment)
        {
            throw new NotImplementedException();
        }

        public void UpdatePayment(Payment payment)
        {
            throw new NotImplementedException();
        }

        public void DeletePayment(Payment payment)
        {
            throw new NotImplementedException();
        }

        public void DeletePaymemntById(int id)
        {
            throw new NotImplementedException();
        }

        public List<PaymentMode> GetAllPaymentModes()
        {
            var business = new Business.TgiService();
            return business.GetAllPaymentModes();
        }
        #endregion

        #region EventVenue
        public List<EventVenue> GetAllEventVenues()
        {
            var business = new Business.TgiService();
            var eventVenues = business.GetAllEventVenues();
            return eventVenues;
        }

        public EventVenue GetEventVenueById(int id)
        {
            var business = new Business.TgiService();
            var eventVenue = business.GetEventVenueById(id);
            return eventVenue;
        }

        public void CreateEventVenue(EventVenue eventVenue)
        {
            var business = new Business.TgiService();
            business.CreateEventVenue(eventVenue);

        }

        public void UpdateEventVenue(EventVenue eventVenue)
        {
            var business = new Business.TgiService();
            business.UpdateEventVenue(eventVenue);
        }

        public void DeleteEventVenue(EventVenue eventVenue)
        {
            var business = new Business.TgiService();
            business.DeleteEventVenue(eventVenue);
        }

        public void DeleteEventVenueById(int id)
        {
            var business = new Business.TgiService();
            business.DeleteEventVenueById(id);
        }
        #endregion

        #region AgentBranch
        public List<AgentBranch> GetAllAgentBranches()
        {
            var business = new Business.TgiService();
            return business.GetAllAgentBranches();
        }

        public AgentBranch GetAgentBranchById(int id)
        {
            throw new NotImplementedException();
        }

        public void CreateAgentBranch(AgentBranch agentBranch)
        {
            throw new NotImplementedException();
        }

        public void UpdateAgentBranch(AgentBranch agentBranch)
        {
            throw new NotImplementedException();
        }

        public void DeleteAgentBranch(AgentBranch agentBranch)
        {
            throw new NotImplementedException();
        }

        public void DeleteAgentBranchById(int id)
        {
            throw new NotImplementedException();
        }
        #endregion

        #region City
        
        public List<City> FindCities(string searchText, int maxResults)
        {
            var business = new Business.TgiService();
            return business.FindCities(searchText, maxResults);
        }
        #endregion
    }
}
